package com.panghl.handler;

import com.panghl.pojo.User;
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler;
import org.apache.poi.xssf.usermodel.XSSFComment;

/**
 * @Author panghl
 * @Date 2022/2/27
 * @Description 百万数据导出sheet处理器
 **/
public class SheetHandler implements XSSFSheetXMLHandler.SheetContentsHandler {

    private User user = null;

    @Override
    public void startRow(int rowNum) { //每一行的开始  rowNum代表的是每个sheet的行索引
        if (rowNum == 0) {
            user = null;
        } else {
            user = new User();
        }
    }

    @Override //每一行的结束
    public void endRow(int rowNum) {
        if (rowNum != 0) {
            System.out.println(user);
        }
    }

    @Override  //处理每一行的所有单元格
    public void cell(String cellName, String cellValue, XSSFComment xssfComment) {
        if (user == null) return;

        String letter = cellName.substring(0, 1); //获取每个单元格名称的首字母 A B C D
        switch (letter) {
            case "A":
                user.setId(Long.parseLong(cellValue));
                break;
            case "B":
                user.setUserName(cellName);
                break;
            case "C":
            case "D":
            case "E":
        }

    }
}
